package kn.tool.type.change;

/**
 * @author: dengkunnan
 * @date: 2020-07-12 18:18
 * @description: 首字母大小写转换，范围判断工具类集合
 **/
public class LetterCaseConversion {
    /**
     * @param str oldstr
     * @param str newstr
     * @descrption 字符串首字母转小写
     */
    public static String lowerFirst(String str) {
        if (isNull(str)) {
            return "";
        }
        char[] chars = str.toCharArray();

        if (!(charIs_AZ(chars[0]) || charIs_az(chars[0]))) {
            return "";
        }
        if (chars[0] >= 65 && chars[0] <= 90) {
            chars[0] += 32;
        }
        return String.valueOf(chars);
    }


    /**
     * @param str oldstr
     * @param str newstr
     * @descrption 字符串首字母转大写
     */
    public static String increaseFirst(String str) {
        if (isNull(str)) {
            return "";
        }
        char[] chars = str.toCharArray();

        if (!(charIs_AZ(chars[0]) || charIs_az(chars[0]))) {
            return "";
        }

        if (chars[0] >= 97 && chars[0] <= 122) {
            chars[0] += 32;
        }
        return String.valueOf(chars);
    }

    static boolean charIs_AZ(char a) {
        if (a >= 65 && a <= 90) {
            return true;
        }
        return false;
    }

    static boolean charIs_az(char a) {
        if (a >= 97 && a <= 122) {
            return true;
        }
        return false;
    }


    /**
     * @param o Object
     * @return true/false
     */
    public static boolean isNull(Object o) {
        if (o == null) {
            return true;
        }
        if ("".equals(o)) {
            return true;
        }
        return false;
    }
}
